﻿using B.S.DataBase.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.Write.API.Appicant.Command.MeonCommand;
using MediatR;

namespace B.S.DataBase.Write.API.Appicant.CommandHandler.MeonCommandHandler
{
    public class UpdateTounCommHneders : IRequestHandler<UpdateTounCommder, APIResult<object>>
    {

        private readonly IBaseRepository<TrunMeon> baseRepository;

        public UpdateTounCommHneders(IBaseRepository<TrunMeon> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<object>> Handle(UpdateTounCommder request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();

            result.Code = APIEnum.审批成功;
            result.Msg =APIEnum.审批成功.ToString();

            var list = baseRepository.GetAll().Result.FirstOrDefault(x => x.Trunid == request.Trunid);
            list.Name = request.Name;
            list.DepId = request.DepId;
            list.IeaveType = request.IeaveType;
            list.StartDate = request.StartDate;
            list.EndDate = request.EndDate;
            list.TotalDays = request.TotalDays;
            list.TotalHours = request.TotalHours;
            list.ReportDate = request.ReportDate;
            list.Reason = request.Reason;
            list.Cause = request.Cause;
            if (list.Ieader=="二二") 
            {
                list.Audit = request.Audit;
                list.Suesser =(int)Suess.已完成;
            }
            else if (list.Ieader == "李四")
            {
                list.Audit = request.Audit;
                list.Suesser = (int)Suess.审批中;
            }
            if(list.Audit==true)
            {
                list.Audit = request.Audit;
                list.Suesser = (int)Suess.也拒绝;
            }
            list.Ieader = request.Ieader;


            baseRepository.Update(list);

            return Task.FromResult(result);
        }
    }
}
